package org.hhchat.others.toutiao.p2018;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.TreeSet;

/**
 * Created this one by huminghao on 2018/4/15.
 */


public class MyMain0011 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        in.nextLine();
        List<List<Integer>> duoLines = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int cap = in.nextInt();
            List<Integer> list = new ArrayList<>(cap);
            for (int j = 0; j < cap; j++) {
                list.add(in.nextInt());
            }
            duoLines.add(list);
            in.nextLine();
        }

        for (int i = 0; i < N; i++) {
            List<Integer> a = duoLines.get(i);
            System.out.println(getMinCycle(a));
        }
    }

    public static int getMinCycle(List<Integer> list) {
        int len = list.size();
        int step = 1;
        while (step <= len - 1) {
            long tP = (list.get(step) - list.get(0));
            int tN = (list.get(len - 1) - list.get(len -1 -step));
            int i = 0;
            while (i < len) {
                if (list.get(i) + tP > list.get(len - 1)) {
                    if (isInList(list,false, step, (int)tP))
                        return (int)tP;
                }
                else if (list.get(i+step) - list.get(i) != tP) break;
                i++;
            }
            i = 0;
            while (i < len) {
                if (list.get(len-1 - i) - tN < list.get(0)) {
                    if (isInList(list,true,step,tN))
                        return tN;
                }
                else if (list.get(len-1-i) - list.get(len-1-i-step) != tN) break;
                i++;
            }
            step++;
        }
        return 0;
    }

    public static boolean isInList(List<Integer> list, boolean isP, int step, int t) {
        int len = list.size();
        int i = 0;
        if (isP) {
            while (i + step < len) {
                if (!list.get(i).equals(list.get(i+step) - t)) return false;
                i++;
            }
        }else {
            i = len - 1;
            while (i - step >= 0) {
                if (!list.get(i).equals(list.get(i-step) + t)) return false;
                i--;
            }
        }

        return true;
    }

}
